-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable setting condition on Prometheus Collector #5317
Enable setting condition on Prometheus Collector #5317
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR!
TBH, I would like to have both options available.
The leaderelection is quite specific and is quite handy for users to easily enable the integration on a cluster scope. The generic condition you are adding is also useful but should not replace the leaderelection one. Having both is not only better for the UX but is also useful in case one user wants to add a specific condition like "k8s.label == my-app" while having the leaderelection enabled too.
Hi @ChrsMark understood. I thought about this being a potential option, but wasn't really sure how to implement it, Would you know if there is an existing integration that does something similar that I could use as a reference? |
Thinking about this a bit more, I suppose something like this might work: {{#if (or leaderelection condition)}}
condition: {{#if leaderelection}}${kubernetes_leaderelection.leader} == true{{/if}}{{#if condition}}{{ condition }}{{/if}}
{{/if}} I can't really think of any use-cases that would require a user to set both leaderelection and a condition, but I figure if there is a case, it's probably far enough an edge enough, that a user can just prefix their (I haven't tested the above yet, so not 100% how it will actually work in practice) |
Hi @ChrsMark would you be able to take a look at the change to this PR again when you have a moment and see if this better aligns with the desired state? The hbs file becomes a bit messy with the additional logic, but testing appears to work. Integration Before Upgrade (with Leader Election enabled)inputs:
- id: prometheus/metrics-prometheus-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
name: prometheus-1
revision: 1
type: prometheus/metrics
use_output: default
meta:
package:
name: prometheus
version: 1.1.0
data_stream:
namespace: default
package_policy_id: b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
streams:
- id: >-
prometheus/metrics-prometheus.collector-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
data_stream:
dataset: prometheus.collector
type: metrics
metricsets:
- collector
hosts:
- 'localhost:9090'
metrics_filters.exclude: null
metrics_filters.include: null
metrics_path: /metrics
period: 10s
rate_counters: true
use_types: true
username: user
password: secret
condition: '${kubernetes_leaderelection.leader} == true' Integration After Upgradeinputs:
- id: prometheus/metrics-prometheus-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
name: prometheus-1
revision: 2
type: prometheus/metrics
use_output: default
meta:
package:
name: prometheus
version: 1.2.0
data_stream:
namespace: default
package_policy_id: b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
streams:
- id: >-
prometheus/metrics-prometheus.collector-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
data_stream:
dataset: prometheus.collector
type: metrics
metrics_filters.exclude: null
period: 10s
password: secret
condition: '${kubernetes_leaderelection.leader} == true'
hosts:
- 'localhost:9090'
metricsets:
- collector
use_types: true
metrics_filters.include: null
rate_counters: true
metrics_path: /metrics
username: user Integration After Upgrade (adding a condition)inputs:
- id: prometheus/metrics-prometheus-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
name: prometheus-1
revision: 4
type: prometheus/metrics
use_output: default
meta:
package:
name: prometheus
version: 1.2.0
data_stream:
namespace: default
package_policy_id: b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
streams:
- id: >-
prometheus/metrics-prometheus.collector-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
data_stream:
dataset: prometheus.collector
type: metrics
metrics_filters.exclude: null
period: 10s
password: secret
condition: '${kubernetes_leaderelection.leader} == true and k8s.label == my-app'
hosts:
- 'localhost:9090'
metricsets:
- collector
use_types: true
metrics_filters.include: null
rate_counters: true
metrics_path: /metrics
username: user Integration After Upgrade (Disabling leader election)inputs:
- id: prometheus/metrics-prometheus-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
name: prometheus-1
revision: 5
type: prometheus/metrics
use_output: default
meta:
package:
name: prometheus
version: 1.2.0
data_stream:
namespace: default
package_policy_id: b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
streams:
- id: >-
prometheus/metrics-prometheus.collector-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
data_stream:
dataset: prometheus.collector
type: metrics
metrics_filters.exclude: null
period: 10s
password: secret
condition: k8s.label == my-app
hosts:
- 'localhost:9090'
metricsets:
- collector
use_types: true
metrics_filters.include: null
rate_counters: true
metrics_path: /metrics
username: user Integration After Upgrade (Removing condition)inputs:
- id: prometheus/metrics-prometheus-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
name: prometheus-1
revision: 6
type: prometheus/metrics
use_output: default
meta:
package:
name: prometheus
version: 1.2.0
data_stream:
namespace: default
package_policy_id: b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
streams:
- id: >-
prometheus/metrics-prometheus.collector-b7e2f2ce-8b43-4fca-a1bf-c9b9606c9b5a
data_stream:
dataset: prometheus.collector
type: metrics
metrics_filters.exclude: null
period: 10s
password: secret
hosts:
- 'localhost:9090'
metricsets:
- collector
use_types: true
metrics_filters.include: null
rate_counters: true
metrics_path: /metrics
username: user A note, after thinking about this for a bit, I've opted to include an |
Hey @BenB196 ! You can find a similar PR that adds the I don't think it's a good idea to mix the So the ...
{{#if leaderelection}}
condition: ${kubernetes_leaderelection.leader} == true
{{/if}}
{{#if condition}}
condition: {{ condition }}
{{/if}}
... If any of these 2 are omitted in the input the respective section will be ignored when Agent "compiles" the above file. This means that as a user I can enable the |
@ChrsMark but in the case you suggested we might get
I didn't test it, do you know if |
@tetianakravchenko yeap you are right about this, only 1 condition is accepted most probably. This means my previous comment is totally invalid, and @BenB196 please ignore it. Apologies for any confusion. I think how it's currently shaped is fine:
@BenB196 if both are set by the user then the @tetianakravchenko wdyt? |
@ChrsMark yes, I agree, how it's currently shaped is fine. optionally
|
🌐 Coverage report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I also tested this branch on my end and the generated policies for each combination look good.
Package prometheus - 1.2.0 containing this change is available at https://epr.elastic.co/search?package=prometheus |
* Enable setting condition on Prometheus Collector * Fixed missed update of manifest * exclude condition if null * Re-add lost change to condition required * Re-add leaderelection with condition * Fix leaderelection required
* Enable setting condition on Prometheus Collector * Fixed missed update of manifest * exclude condition if null * Re-add lost change to condition required * Re-add leaderelection with condition * Fix leaderelection required
Enhancement
What does this PR do?
In the Prometheus Collector, switch from
condition
being a toggle for Leader Election only, to a text field.Checklist
changelog.yml
file.Author's Checklist
I'm not sure what the policy for this type of change is, but when upgrading existing Integrations via this change, it will blank out an existing leader election condition, if one was previously set:
Integration Before Upgrade
Integration After Upgrade (with no user intervention)
Integration After Upgrade (with user manually re-adding Leader Election condition)
How to test this PR locally
Related issues
condition
#5259Screenshots